package com.artmofang.common.utils;

import org.apache.commons.codec.binary.Base64;

import java.math.BigInteger;
import java.security.MessageDigest;

public class MD5Utils {

	/**
	 * 
	 * @Title: MD5Utils.java
	 * @Package com.imooc.utils
	 * @Description: 对字符串进行md5加密
	 */
	public static String getMD5Str(String strValue) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		String newstr = Base64.encodeBase64String(md5.digest(strValue.getBytes()));
		return newstr;
	}

	public static String MD5Str(String strValue) throws Exception {
		//1. 获得md5加密算法工具类
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		//2. 加密的结果为十进制
		byte[] md5Bytes = messageDigest.digest(strValue.getBytes());
		//3. 将md5加密算法值转化为16进制
		BigInteger bigInteger = new BigInteger(1, md5Bytes);
		return bigInteger.toString(16);
	}

	public static void main(String[] args) {
		try {
			String md5 = MD5Str("123456");
			System.out.println(md5);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
